package com.service.Impl;

import com.bean.User;
import com.dao.UserDao;
import com.service.UserService;
import com.utils.MD5Salt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 末日流光
 * @ClASSNAME UserServiceImpl
 * @PACKAGE_NAME com.service.Impl
 * @date 2022/5/12 21:09
 * @project SSM-demo1
 * @company dzy
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public User adminlogin(String username, String password) {
        //password= MD5Salt.toMD5HutoolSalt(password);
        return userDao.adminlogin(username,password);
    }

    @Override
    public List<User> getUsersByPage(int page, int limit) {
        int start = (page-1)*limit;
        return userDao.getUsersByPage(start,limit);
    }

    @Override
    public int getUserLength() {
        return userDao.getUserLength();
    }

    @Override
    public int addUser(User user) {
        String password=user.getPassword();
        //password=MD5Salt.toMD5HutoolSalt(password);
        user.setPassword(password);
        return userDao.addUser(user);
    }

    @Override
    public List<User> getUsers() {
        return userDao.getUsers();
    }

    @Override
    public int delUserById(int id) {
        return userDao.delUserById(id);
    }

    @Override
    public User selectUserById(int id) {
        return userDao.selectUserById(id);
    }

    @Override
    public int updateUserById(User user) {
        String password=user.getPassword();
        //password=MD5Salt.toMD5HutoolSalt(password);
        user.setPassword(password);
        return userDao.updateUserById(user);
    }
}

